class Solution(object):
    def stringMatching(self, words):
        def judge(a, b):
            if len(a) == len(b):
                return False
            if len(a) > len(b):
                a, b = b, a
            right = 0
            m1 = len(a)
            m2 = len(b)
            while right <= m2 - m1:
                if a == b[right: right + m1]:
                    return a
                else:
                    right += 1
            return False
        out = set()
        n = len(words)
        for i in range(n):
            for j in range(i + 1, n):
                val = judge(words[i], words[j])
                if val:
                    out.add(val)
        return list(out)

